/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2018 All Rights Reserved.
 */
package com.antcloud.demo.antscheduler.nine1nine;

import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

import com.alipay.account.facade.AccountTransService;
import com.alipay.account.facade.com.alipay.account.dto.AccountDTO;
import com.alipay.antschedulerclient.common.ClientCommonResult;
import com.alipay.antschedulerclient.handler.ISimpleJobHandler;
import com.alipay.antschedulerclient.model.JobExecuteContext;
import com.antcloud.demo.antscheduler.dal.daointerface.BillItemDAO;
import com.antcloud.demo.antscheduler.dal.dataobject.BillItemDO;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author qian.lqlq
 * @version $Id: GetAccountBalance.java, v 0.1 2018年09月06日 12:36 qian.lqlq Exp $
 */
public class GetAccountBalance implements ISimpleJobHandler {

    @Autowired
    AccountTransService accountTransService;

    @Autowired
    private BillItemDAO billItemDAO;

    @Override
    public ClientCommonResult handle(JobExecuteContext context) throws Exception {
        billItemDAO.deleteByType(BillItemTypeEnum.BALANCE.name());
        List<AccountDTO> accountDTOList = accountTransService.getAllAccounts();
        for (AccountDTO accountDTO : accountDTOList) {
            BillItemDO billItemDO = new BillItemDO();
            billItemDO.setType(BillItemTypeEnum.BALANCE.name());
            billItemDO.setAmount(accountDTO.getAmount());
            billItemDO.setUserId(accountDTO.getUserId());
            billItemDAO.insert(billItemDO);
        }
        context.putCustomParams("isNotify", true);
        return ClientCommonResult.buildSuccessResult();
    }

    @Override
    public String getName() {
        return "getAccountBalance";
    }

    @Override
    public ThreadPoolExecutor getThreadPool() {
        return null;
    }
}